home *** CD-ROM | disk | FTP | other *** search
- Path: spot.Colorado.EDU!karki
- From: karki@spot.Colorado.EDU (KARKI JITENDRA BAHADUR)
- Newsgroups: comp.lang.c++
- Subject: [Q] Why does this code crash my compiler?
- Date: 7 Apr 96 19:30:27 GMT
- Organization: University of Colorado at Boulder
- Message-ID: <karki.828905427@spot.Colorado.EDU>
- NNTP-Posting-Host: spot.colorado.edu
- Summary: The code compiles ok piece-by-piece, but crashes as a whole.
- Keywords: Watcom template istream conversion
- X-Newsreader: NN version 6.5.0 #8 (NOV)
-
- The following code compiles and runs ok on Watcom C++ 10.0a if either
- of the #defines is commented out, but with both of them in force, it
- causes an access violation during compilation.
- Is the code really bad enough to crash the compiler, or should I get
- a new compiler? Could anyone try compiling it to see if it's a code
- problem or a compiler problem?
-
-
- #include <iostream.h>
- #define make_xxx
- #define inp_xxx
-
- template<class stuff>
- class XXX
- {
- private:
- stuff item;
- public:
- XXX();
- XXX(stuff);
- ~XXX();
- operator int();
- #ifdef inp_xxx
- friend istream& operator >>(istream& ins, XXX<stuff>& a);
- #endif
- };
- template<class stuff>
- XXX<stuff>::XXX()
- {
- }
- template<class stuff>
- XXX<stuff>::XXX(stuff a)
- {
- item = a;
- }
- template<class stuff>
- XXX<stuff>::operator int()
- {
- return 11;
- }
- template<class stuff>
- XXX<stuff>::~XXX()
- {
- cout << "XXX gone" << endl;
- }
- #ifdef inp_xxx
- template<class stuff>
- istream& operator >>(istream& ins, XXX<stuff>& a)
- {
- cout << "Enter the XXX value:> ";
- stuff item;
- ins >> item;
- a.item = item;
- return ins;
- }
- #endif
-
- template<class stuff>
- class YYY
- {
- private:
- stuff item;
- public:
- YYY();
- ~YYY();
- operator int();
- #ifdef make_xxx
- operator XXX<stuff>();
- #endif
- };
- template<class stuff>
- YYY<stuff>::YYY()
- {
- item = 0;
- }
- template<class stuff>
- YYY<stuff>::~YYY()
- {
- cout << "YYY gone" << endl;
- }
- template<class stuff>
- YYY<stuff>::operator int()
- {
- return 7;
- }
- #ifdef make_xxx
- template<class stuff>
- YYY<stuff>::operator XXX<stuff>()
- {
- XXX<stuff> a(item);
- return a;
- }
- #endif
-
- main()
- {
- XXX<int> x;
- YYY<unsigned> y;
- XXX<unsigned> z;
- #ifdef inp_xxx
- cin >> x;
- #endif
- cout << "Ok so far\n";
- int i;
- i = y;
- cout << i << endl;
- #ifdef make_xxx
- z = y;
- #endif
- }
-